package cn.jiyun.controller;

import cn.jiyun.common.R;
import cn.jiyun.pojo.SC;
import cn.jiyun.service.SetmealSerivce;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("setmeal")
public class SetmealController {
    @Autowired
    private SetmealSerivce setmealSerivce;

    @GetMapping("page")
    public R page(Integer page, Integer pageSize, String  name){
        Page<SC> page1=new Page<>(page,pageSize);
        return setmealSerivce.page(page1,name);
    }

    @PostMapping("/status/1")
    public R status1(Long [] ids){
        for (Long id : ids) {
            setmealSerivce.status1(id);
        }
        return R.success("成功");
    }

    @PostMapping("/status/0")
    public R status0(Long [] ids){
        for (Long id : ids) {
            setmealSerivce.status0(id);
        }
        return R.success("成功");
    }

    @DeleteMapping
    public R del(Long [] ids , HttpSession session){
        Long idc= (Long) session.getAttribute("employee");
        for (Long id : ids) {
            setmealSerivce.del(id);
        }
        return R.success("成功");
    }

    @PostMapping
    public R add(@RequestBody SC cs, HttpSession session){
        Long id= (Long) session.getAttribute("employee");
        return R.success(setmealSerivce.add(cs,id));
    }

    @GetMapping("{id}")
    public R hx(@PathVariable Long id){
      SC s=  setmealSerivce.hx(id);
        return R.success(s);
    }

    @PutMapping
    public R update(@RequestBody SC cs, HttpSession session){
        Long id= (Long) session.getAttribute("employee");
        return R.success(setmealSerivce.update(cs,id));
    }

}
